﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：徐彦龙 
    //
    // 文件名：DistributeRelationInfo.cs
    // 文件功能描述：配送关系详情
    // 创建标识：吕海乐2009-04-03
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：页面作废 2009-6-4 李刚
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.BidProdManage
{
    public partial class DistributeRelationInfo : BasePage
    {
        public DistributeRelationInfo()
        {
            this.ModuleNo = Module.配送关系管理.ToString();
        }

        IBLL_Distribution id = Factory.BLL_Distribution();
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        protected void Page_Load(object sender, EventArgs e)
        {
            string procureCatalogId = Request.QueryString["procureCatalogId"].ToString();
            ViewState["v_procureCatalogId"] = procureCatalogId;
            if (!IsPostBack)
            {
                Model.View.ProcureCatalog procureCatalog = ipb.GetProcureCatalogByID(procureCatalogId);
                lblCompany_SC.Text = procureCatalog.CompanyName_SC;
                lblCompany_ZB.Text = procureCatalog.CompanyName_TB;
                lblGoodsName.Text = procureCatalog.GoodsName;
                lblMaterial.Text = procureCatalog.Material;
                lblOutlookc.Text = procureCatalog.Outlookc;
                lblUnit.Text = procureCatalog.Unit;
                SetBind();
            }
        }

        /// <summary>
        /// 绑定相关的配送关系
        /// </summary>
        private void SetBind()
        {
            string procureCatalogId = ViewState["v_procureCatalogId"].ToString();
            HZ.DrugTrade.Model.Query.DistributionRelation aDistributionRelation = new HZ.DrugTrade.Model.Query.DistributionRelation();
            aDistributionRelation.ProcureCatalogID = procureCatalogId;
            aDistributionRelation.Hospital_IsUsing = true;
            aDistributionRelation.SortFields = "CompanyName_PS asc";

            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            gvwDRInfo.PageSize = AspNetPager1.PageSize;
            int totalCount = 0;
            IList<HZ.DrugTrade.Model.View.DistributionRelation> distibutionRelationList = id.GetDistributionByWhere(aDistributionRelation, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwDRInfo.DataSource = distibutionRelationList;
            gvwDRInfo.DataBind();
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

        /// <summary>
        /// 启用、禁用配送关系
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwDRInfo_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "IsUsing")
            {
                DistributionRelation aDistributionRelation = new DistributionRelation();

                //从CommandArgument中取出IsUsing、hospitalId和companyID
                string  strCmdArgment = e.CommandArgument.ToString();
                string[] array = strCmdArgment.Split(';');
                string isUsing = array[0];
                string hospitalID = array[1];
                string companyID = array[2];

                //定义DistributionRelation实体
                if (isUsing == "True")
                {
                    aDistributionRelation.IsUsing = false;
                }
                else if(isUsing=="False")
                {
                    aDistributionRelation.IsUsing = true;
                }
                aDistributionRelation.ProcureCatalogID = ViewState["v_procureCatalogId"].ToString();
                aDistributionRelation.HospitalID = hospitalID;
                aDistributionRelation.CompanyID_PS = companyID;
                
                //执行操作
                int flag = id.UpdateDistribution_IsUsing(aDistributionRelation);
                if (flag == 1)
                {
                    SetBind();
                }
                else
                {
                    PageError("无法进行此操作！", this.ReturnUrl);
                }
            }
        }
    }
}
